package entities;

/**
 * @author Omri Barda		039725890 
 * @author Amit Joseph		034608547
 * @author Gilad Shpigel  	300162393
 * @author Elad Elbaz		040539959
 * @version June 2012
 */

import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;

public class Exam implements Serializable {
	private static final long serialVersionUID = 1L;
	final public static int ERROR = 99999;

	private int examID;
	private int courseID;
	private int subjectID;
	private Date examCreationDate;
	private Date examDurationTime;
	private int examLecturerID;
	private String examStudentInstructions;
	private String examLecturerInstructions;
	private ArrayList<QuestionPerExam> examQuestions;

	/**
	 * Constructor
	 * 
	 * @param examID
	 * @param examCreationDate
	 * @param examDurationTime
	 * @param examCreatorID
	 * @param examStudentInstructions
	 * @param examLecturerInstructions
	 */
	public Exam(int examID, Date examCreationDate, Date examDurationTime,
			int examCreatorID, String examStudentInstructions,
			String examLecturerInstructions) {
		super();
		this.examID = examID;
		this.examCreationDate = examCreationDate;
		this.examDurationTime = examDurationTime;
		this.examLecturerID = examCreatorID;
		this.examStudentInstructions = examStudentInstructions;
		this.examLecturerInstructions = examLecturerInstructions;
		this.examQuestions = new ArrayList<QuestionPerExam>();
	}

	/**
	 * empty Constructor
	 */
	public Exam() {
	}

	/**
	 * adding question to the exam
	 * 
	 * @param qpe
	 */
	public void addQuestion(QuestionPerExam qpe) {
		examQuestions.add(qpe);
	}

	/**
	 * adding array of questions to the exam
	 * 
	 * @param qpelst
	 */
	public void addQuestion(ArrayList<QuestionPerExam> qpelst) {
		if (examQuestions == null)
			examQuestions = new ArrayList<QuestionPerExam>();
		examQuestions.addAll(qpelst);
	}

	/**
	 * getting a question of the exam
	 * 
	 * @param qNumber
	 *            the question index
	 * @return the question
	 */
	public QuestionPerExam getQuestion(int qNumber) {
		return examQuestions.get(qNumber);
	}

	/**
	 * removing a question from the exam
	 * 
	 * @param qpe
	 */
	public void removeQuestion(QuestionPerExam qpe) {
		examQuestions.remove(qpe);
	}

	// ------------------
	// Setters & Getters
	// ------------------
	/**
	 * 
	 * @return the exam ID
	 */
	public int getExamID() {
		return examID;
	}

	/**
	 * 
	 * @param examID
	 *            of the exam
	 * @return whether the ID is legal
	 */
	public Boolean setExamID(Integer examID) {
		if ((examID > 99) && (examID <= 999999)) {
			this.examID = new Integer(examID.intValue() % 100);
			this.setCourseID(new Integer((examID.intValue() / 100) % 100));
			this.setSubjectID(new Integer(examID.intValue() / 10000));
		} else if ((examID >= 0) && (examID < 100))
			this.examID = examID;
		else
			return false;
		return true;
	}

	/**
	 * 
	 * @return the exam questions
	 */
	public ArrayList<QuestionPerExam> getExamQuestionsArr() {
		return examQuestions;
	}

	/**
	 * 
	 * @return the exam number of questions
	 */
	public int getNumOfQuestions() {
		return examQuestions.size();
	}

	/**
	 * 
	 * @return the exam creation date
	 */
	public Date getExamCreationDate() {
		return examCreationDate;
	}

	/**
	 * 
	 * @param examCreationDate
	 *            of the exam
	 */
	public void setExamCreationDate(Date examCreationDate) {
		this.examCreationDate = examCreationDate;
	}

	/**
	 * 
	 * @return the exam duration time
	 */
	public Date getExamDurationTime() {
		return examDurationTime;
	}

	/**
	 * 
	 * @param examDurationTime
	 *            of the exam
	 */
	public void setExamDurationTime(Date examDurationTime) {
		this.examDurationTime = examDurationTime;
	}

	/**
	 * 
	 * @return the exam lecturer ID
	 */
	public int getExamLecturerID() {
		return examLecturerID;
	}

	/**
	 * 
	 * @param examCreatorID
	 *            of the exam
	 */
	public void setExamLecturerID(int examCreatorID) {
		this.examLecturerID = examCreatorID;
	}

	/**
	 * 
	 * @return the exam student instructions
	 */
	public String getExamStudentInstructions() {
		return examStudentInstructions;
	}

	/**
	 * 
	 * @param examStudentInstructions
	 *            of the exam
	 */
	public void setExamStudentInstructions(String examStudentInstructions) {
		this.examStudentInstructions = examStudentInstructions;
	}

	/**
	 * 
	 * @return the exam lecturer instructions
	 */
	public String getExamLecturerInstructions() {
		return examLecturerInstructions;
	}

	/**
	 * 
	 * @param examLecturerInstructions
	 *            of the exam
	 */
	public void setExamLecturerInstructions(String examLecturerInstructions) {
		this.examLecturerInstructions = examLecturerInstructions;
	}

	/**
	 * 
	 * @return the exam course ID
	 */
	public int getCourseID() {
		return courseID;
	}

	/**
	 * 
	 * @param crsID
	 *            of the exam
	 */
	public void setCourseID(int crsID) {
		this.courseID = crsID;
	}

	/**
	 * 
	 * @return the exam subject ID
	 */
	public int getSubjectID() {
		return subjectID;
	}

	/**
	 * 
	 * @param subjectID
	 *            of the exam
	 */
	public void setSubjectID(int subjectID) {
		this.subjectID = subjectID;
	}

}
